﻿using System;
using System.Linq;
using System.Reflection;
using System.Windows;

namespace JY.Wpf.Core.Extensions
{
    /// <summary>
    /// 字符串扩展
    /// </summary>
    public static class StringExtension
    {
        #region # 获取类路径字符串类型方法——Type GetPathType(this string path)
        /// <summary>
        /// 获取类路径字符串类型方法
        /// </summary>
        public static Type GetPathType(this string path)
        {
            Assembly assembly = Application.Current.GetType().Assembly;
            Type result = assembly.GetType(path);
            if (result == null)
            {
                assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly subAssembly) => path.Contains(subAssembly.FullName.Substring(0, subAssembly.FullName.IndexOf(",", StringComparison.Ordinal))));
            }
            result = assembly?.GetType(path);
            return result;
        }
        #endregion
    }
}
